<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title></title>
<#include "/jeecms_sys/head.html"/>
<script type="text/javascript">
function getTableForm() {
	return document.getElementById('tableForm');
}
function optDelete() {
	if(Pn.checkedCount('ids')<=0) {
		$.alert("<@s.m 'global.prompt'/>","<@s.m 'error.checkRecord'/>");
		return;
	}
	$.confirm(doDelete,"<@s.m 'global.confirm'/>","<@s.m 'global.confirm.delete'/>");
}
function doDelete(){
	var f = getTableForm();
	f.action="o_delete.do";
	f.submit();
}
function checkValue(msgId,formId){
	var flag=true;
	if($("#"+formId+" input[name='value']").val()!=""){
		$.post("v_check_value.do",
				{
					value:$("#"+formId+" input[name='value']").val(),
					type:$("#"+formId+" input[name='type']").val()
				},
				function(data) {
					if(data.pass=="false"){
						$("#"+msgId).html("");
					}else{
						$("#"+msgId).html("<@s.m 'cmsDictionary.value.repeat'/>");
						}
				}, "json");
	}else{
		flag=false;
		$("#"+msgId).html("");
	}
	if($("#"+msgId).html()!=""){
		flag=false;
	}
	return flag;
}
$(function() {
	$("#addForm").validate();
	$("#editForm").validate();
	$("#dialog-add-form").dialog({
		autoOpen: false,
		height: 300,
		width: 500,
		modal: true,
		buttons: {
			"<@s.m code='global.submit'/>": function() {
				if($("#addMsgSpan").html()==""){
					$("#addForm").submit();
				}
				var errorlength=$(".error").length;
				if(errorlength<0){
					$( this ).dialog( "close" );
				}
			},
			"<@s.m code='global.reset'/>": function() {
				$("#addForm")[0].reset();
			}
		}
	});
	$("#dialog-edit-form").dialog({
		autoOpen: false,
		height: 300,
		width: 500,
		modal: true,
		buttons: {
			"<@s.m code='global.submit'/>": function() {
				if($("#editMsgSpan").html()==""){
					$("#editForm").submit();
				}
				var errorlength=$(".error").length;
				if(errorlength<0){
					$( this ).dialog( "close" );
				}
			},
			"<@s.m code='global.reset'/>": function() {
				$("#editForm")[0].reset();
			}
		}
	});
	$(".add").click(function() {
		$( "#dialog-add-form" ).dialog("open");
	});
	$("a[id^='edit_']").click(function() {
		getData($(this).attr("id").split("edit_")[1]);//获取json数据  
		$( "#dialog-edit-form" ).dialog("open");
	});
});
function getData(id){
    $.getJSON("v_ajax_edit.do",{id:id},function(data){  
        $("#editForm input[name='name']").val(data.name); 
        $("#editForm input[name='id']").val(data.id); 
        $("#editForm input[name='type']").val(data.type); 
        $("#editForm input[name='value']").val(data.value); 
  });  
}
</script>
</head>
<body>

<div class="box-positon">
	<div class="rpos"><@s.m "global.position"/>: <@s.m "cmsDictionary.function"/> - <@s.m "global.list"/></div>
		<input  class="add" value="<@s.m "global.add"/>" />
	<div class="clear"></div>
</div>
<div class="body-box">
<form action="v_list.do" method="post" style="padding-top:5px; padding-left:10px;">
<div>
<@p.select name="queryType" value=queryType list=typeList headerKey="" headerValue="cmsDictionary.type.allType"/>
<input class="query" type="submit" value="<@s.m "global.query"/>"/>
</div>
</form>
<form id="tableForm" method="post">
<input type="hidden" name="pageNo" value="${pageNo!}"/>
<input type="hidden" name="queryType" value="${queryType!}"/>
<@p.table value=pagination;cmsDictionary,i,has_next><#rt/>
	<@p.column title="<input type='checkbox' onclick='Pn.checkbox(\"ids\",this.checked)'/>" width="25" align="center">
		<input type='checkbox' name='ids' value='${cmsDictionary.id}' onclick="Pn.selectCheckBox('${cmsDictionary.id}',this.checked)"/><#t/>
	</@p.column><#t/>
	<@p.column title="ID" align="center">${cmsDictionary.id}</@p.column><#t/>
	<@p.column code="cmsDictionary.name" align="center">${cmsDictionary.name!}</@p.column><#t/>
	<@p.column code="cmsDictionary.value" align="center">${cmsDictionary.value!}</@p.column><#t/>
	<@p.column code="cmsDictionary.type" align="center">${cmsDictionary.type}</@p.column><#t/>
	<@p.column code="global.operate" align="center">
		<a href="#" class="pn-opt" id="edit_${cmsDictionary.id}"><@s.m "global.edit"/></a> | <#rt/>
		<a href="o_delete.do?ids=${cmsDictionary.id}&pageNo=${pageNo!}" onclick="if(!$.confirmToUrl(this.href)) {return false;}" class="pn-opt"><@s.m "global.delete"/></a><#t/>
	</@p.column><#t/>
</@p.table>
<div style="background:url(${base}/res/common/img/theme/boxTitleBG.jpg) repeat-x; height:20px; overflow:hidden;">
<input type="button" value="<@s.m "global.delete"/>" onclick="optDelete();" class="del-button"/ style="float:left; border-right:1px solid #ffffff;">
</div>
</form>

<div id="dialog-add-form" title="<@s.m 'cmsDictionary.function'/> - <@s.m 'global.add'/>">
	<@p.form id="addForm" action="o_save.do" >
	<@p.text label="cmsDictionary.type" name="type" required="true" class="required" maxlength="20" />
	<@p.text label="cmsDictionary.name" name="name" required="true" class="required" maxlength="20" />
	<@p.td colspan="2" label="cmsDictionary.value">
	<@p.text  name="value" id="addValue" required="true" class="required" maxlength="20" onblur="checkValue('addMsgSpan','addForm')"/>
	<span style="color: red;" id="addMsgSpan"></span>
	</@p.td><@p.tr/>
	</@p.form>
</div>

<div id="dialog-edit-form" title="<@s.m 'cmsDictionary.function'/> - <@s.m 'global.edit'/>">
	<@p.form id="editForm" action="o_update.do" >
	<@p.text label="cmsDictionary.type" name="type" required="true" class="required" maxlength="20" />
	<@p.text label="cmsDictionary.name" name="name" required="true" class="required" maxlength="20" />
	<@p.td colspan="2" label="cmsDictionary.value">
	<@p.text  name="value" id="editValue" required="true" class="required" maxlength="20" onblur="checkValue('editMsgSpan','editForm')"/>
	<span style="color: red;" id="editMsgSpan"></span>
	</@p.td><@p.tr/>
	<@p.hidden name="id" id="id"/>
	</@p.form>
</div>

</div>
<#include "/common/alert_message.html"/>
</body>
</html>